<?php

/**
 * This is the model class for table "event".
 * 
 * 
 * alter table event add share text default null;
 *
 * 
 * The followings are the available columns in table 'event':
 * @property integer $id
 * @property integer $companyid
 * @property string $title
 * @property string $description
 * @property string $adds
 * @property string $award
 * @property integer $hit
 * @property string $starttime
 * @property string $endtime
 */
class Event extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Event the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'event';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('companyid, title ', 'required'),
			array('companyid, hit, thumbnailheight', 'numerical', 'integerOnly'=>true),
			array('title, adds, award', 'length', 'max'=>255),
			array('description', 'length', 'max'=>5000),
			array('share', 'length', 'max'=>2000),
			array('starttime, endtime', 'safe'),
			array('background, thumbnail',  
                'file',    //定义为file类型  
                'allowEmpty'=>true,   
                'types'=>'jpg,png,gif',   //上传文件的类型  
                'maxSize'=>1024*1024*10,    //上传大小限制，注意不是php.ini中的上传文件大小  
                'tooLarge'=>'文件大于10M，上传失败！请上传小于10M的文件！'  
            ),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, companyid, title, description, share, adds, award, hit, background, thumbnail, starttime, endtime, thumbnailheight', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'companyid' => '企业id',
			'title' => '活动标题',
			'description' => '活动内容',
			'share' => '分享内容',
			'adds' => '兑奖方法',
			'award' => '奖项设置',
			'thumbnail' => '封面图',
			'background' => '背景图',
			'hit' => '参与人数',
			'starttime' => '开始时间',
			'endtime' => '结束时间',
			'thumbnailheight' => '封面高度',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('companyid',$this->companyid);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('adds',$this->adds,true);
		$criteria->compare('award',$this->award,true);
		$criteria->compare('thumbnail',$this->thumbnail,true);
		$criteria->compare('background',$this->background,true);
		$criteria->compare('hit',$this->hit);
		$criteria->compare('starttime',$this->starttime,true);
		$criteria->compare('endtime',$this->endtime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}